home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / lang / PPCSmllEiffel.lha / PPCSmallEiffel / lib_se / run_feature_6.e < prev    next >
Text File  |  1998-01-16  |  8KB  |  299 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class RUN_FEATURE_6
  17.    
  18. inherit RUN_FEATURE redefine base_feature end;
  19.  
  20. creation {ONCE_FUNCTION} make
  21.    
  22. feature 
  23.    
  24.    base_feature: ONCE_FUNCTION;
  25.       
  26.    local_vars: LOCAL_VAR_LIST;
  27.    
  28.    is_static: BOOLEAN is do end;
  29.    
  30.    static_value_mem: INTEGER is do end;
  31.  
  32.    afd_check is
  33.       do
  34.      routine_afd_check;
  35.       end;
  36.  
  37.    can_be_dropped: BOOLEAN is 
  38.       do
  39.      if is_pre_computable then
  40.         Result := true;
  41.      end;
  42.       end;
  43.    
  44.    mapping_c is
  45.       local
  46.      tcbd: BOOLEAN;
  47.       do
  48.      if is_pre_computable then
  49.         once_result;        
  50.      elseif use_current then
  51.         default_mapping_function;
  52.      else
  53.         tcbd := cpp.target_cannot_be_dropped;
  54.         if tcbd then
  55.            cpp.put_character(',');
  56.         end;
  57.         mapping_name;
  58.         cpp.put_character('(');
  59.         if arg_count > 0 then
  60.            cpp.put_arguments;
  61.         end;
  62.         cpp.put_character(')');
  63.         if tcbd then
  64.            cpp.put_character(')');
  65.         end;
  66.      end;
  67.       end;
  68.    
  69.    c_define is
  70.       local
  71.      bfbc: BASE_CLASS;
  72.       do
  73.      bfbc := base_feature.base_class;
  74.      if is_pre_computable then
  75.         if not bfbc.once_flag(once_mark) then
  76.            once_variable;
  77.         end;
  78.         cpp.incr_pre_computed_once_count(Current);
  79.      else
  80.         if not bfbc.once_flag(once_mark) then
  81.            once_boolean;
  82.            once_variable;
  83.         end;
  84.         define_prototype;
  85.         cpp.put_string("if (");
  86.         once_flag; 
  87.         cpp.put_string("==0){%N");
  88.         define_opening;
  89.         once_flag;
  90.         cpp.put_string("=1;%N");
  91.         if routine_body /= Void then
  92.            routine_body.compile_to_c;
  93.         end;
  94.         define_closing;
  95.         once_result;
  96.         cpp.put_string("=R;}%N");
  97.         cpp.put_string("return ");
  98.         once_result;
  99.         cpp.put_string(";}%N");
  100.      end;
  101.       end;
  102.    
  103. feature {NONE}   
  104.  
  105.    is_pre_computable: BOOLEAN is
  106.       do
  107.      if frozen_general.fast_has(name.to_string) then
  108.         Result := true;
  109.      elseif arguments = Void and then not use_current then 
  110.         if routine_body = Void then
  111.            Result := true;
  112.         elseif not run_control.invariant_check then
  113.            Result := routine_body.is_pre_computable;
  114.         end;
  115.      end;
  116.       end;
  117.  
  118. feature {ONCE_ROUTINE_POOL}   
  119.  
  120.    once_result_in(str: STRING) is
  121.      -- Produce the C name of the once Result.
  122.       do
  123.      str.extend('o');
  124.      base_feature.mapping_c_name_in(str);
  125.       end;
  126.    
  127. feature {NONE}   
  128.  
  129.    once_result is
  130.      -- Produce the C name of the once Result.
  131.       do
  132.      c_code.clear;
  133.      once_result_in(c_code);
  134.      cpp.put_string(c_code);
  135.       end;
  136.    
  137.    once_variable is
  138.       do
  139.      c_code.clear;
  140.      c_code.extend('T');
  141.      if result_type.is_expanded then
  142.         result_type.id.append_in(c_code);
  143.         c_code.extend(' ');
  144.      else
  145.         c_code.extend('0');
  146.         c_code.extend('*');
  147.      end;
  148.      once_result_in(c_code);
  149.      c_code2.clear;
  150.      result_type.c_initialize_in(c_code2);
  151.      cpp.put_extern5(c_code,c_code2);
  152.       end;
  153.    
  154.    initialize is
  155.       do
  156.      arguments := base_feature.arguments;
  157.      if arguments /= Void and then arguments.count > 0 then
  158.         arguments := arguments.to_runnable(current_type);
  159.      end;
  160.      result_type := base_feature.result_type;
  161.      if result_type.is_anchored then
  162.         eh.add_position(result_type.start_position);
  163.         fatal_error("Result type of a once function must %
  164.             %not be anchored (VFFD.7).");
  165.      elseif result_type.is_formal_generic then
  166.         eh.add_position(result_type.start_position);
  167.         fatal_error("Result type of a once function must %
  168.             %not be a formal generic argument (VFFD.7).");
  169.      end;
  170.      result_type := result_type.to_runnable(current_type);
  171.      local_vars := base_feature.local_vars;
  172.      if local_vars /= Void and then local_vars.count > 0 then
  173.         local_vars := local_vars.to_runnable(current_type);
  174.      end;
  175.      routine_body := base_feature.routine_body;
  176.      if routine_body /= Void then
  177.         routine_body := routine_body.to_runnable(current_type);
  178.      end;
  179.      if run_control.require_check then
  180.         require_assertion := base_feature.run_require(Current);
  181.      end;
  182.      if run_control.ensure_check then
  183.         ensure_assertion := base_feature.run_ensure(Current);
  184.      end;
  185.      once_routine_pool.add_function(Current);
  186.       end;
  187.    
  188.    compute_use_current is
  189.       do
  190.      std_compute_use_current;
  191.       end;
  192.    
  193. feature {NONE}
  194.    
  195.    frozen_general: ARRAY[STRING] is
  196.       once
  197.      Result := <<us_std_error, us_std_input, us_io, 
  198.              us_std_output>>;
  199.       end;
  200.    
  201. feature {C_PRETTY_PRINTER}
  202.    
  203.    c_pre_computing is
  204.       require
  205.      is_pre_computable;
  206.      cpp.on_c;
  207.       local
  208.      bfbc: BASE_CLASS;
  209.       do
  210.      bfbc := base_feature.base_class;
  211.      echo.put_character('%T');
  212.      echo.put_string(bfbc.base_class_name.to_string);
  213.      echo.put_character('.');
  214.      echo.put_string(name.to_string);
  215.      echo.put_character('%N');
  216.      if run_control.require_check then
  217.         if require_assertion /= Void then
  218.            require_assertion.compile_to_c;
  219.         end;
  220.      end;
  221.      tmp_string.clear;
  222.      tmp_string.extend('{');
  223.      result_type.c_type_for_result_in(tmp_string);
  224.      tmp_string.extend(' ');
  225.      tmp_string.extend('R');
  226.      tmp_string.extend('=');
  227.      cpp.put_string(tmp_string);
  228.      result_type.c_initialize;
  229.      cpp.put_string(fz_00);
  230.      if local_vars /= Void then
  231.         local_vars.compile_to_c;
  232.      end;
  233.      if routine_body /= Void then
  234.         routine_body.compile_to_c; 
  235.      end;
  236.      if run_control.ensure_check then
  237.         if ensure_assertion /= Void then
  238.            ensure_assertion.compile_to_c;
  239.         end;
  240.      end;
  241.      once_result;
  242.      cpp.put_string("=R;}/*PCO*/%N");
  243.       end;
  244.  
  245.    tmp_string: STRING is
  246.       once
  247.      !!Result.make(10);
  248.       end;
  249.  
  250. feature {RUN_CLASS}
  251.  
  252.    jvm_field_or_method is
  253.       do
  254.      jvm.add_method(Current);
  255.       end;
  256.  
  257. feature
  258.  
  259.    mapping_jvm is
  260.       do
  261.      routine_mapping_jvm;
  262.       end;
  263.  
  264. feature {JVM}
  265.  
  266.    jvm_define is
  267.       local
  268.      result_space, branch, idx_flag, idx_result: INTEGER;
  269.       do
  270.      idx_result := once_routine_pool.idx_fieldref_for_result(Current);
  271.      idx_flag := once_routine_pool.idx_fieldref_for_flag(Current);
  272.      result_space := result_type.jvm_stack_space;
  273.      method_info_start;
  274.      code_attribute.opcode_getstatic(idx_flag,1);
  275.      branch := code_attribute.opcode_ifne;
  276.      code_attribute.opcode_iconst_1;
  277.      code_attribute.opcode_putstatic(idx_flag,-1);
  278.      jvm_define_opening;
  279.      if routine_body /= Void then
  280.         routine_body.compile_to_jvm;
  281.      end;
  282.      jvm_define_closing;
  283.      code_attribute.opcode_putstatic(idx_result,- result_space);
  284.      code_attribute.resolve_u2_branch(branch);
  285.      code_attribute.opcode_getstatic(idx_result,result_space);
  286.      result_type.run_type.jvm_return_code;
  287.      method_info.finish;
  288.       end;
  289.    
  290. feature {NONE}
  291.  
  292.    update_tmp_jvm_descriptor is
  293.       do
  294.      routine_update_tmp_jvm_descriptor;
  295.       end;
  296.  
  297. end -- RUN_FEATURE_6
  298.  
  299.